import 'package:flutter/material.dart';
import 'package:get/get.dart';
import 'package:my_flutter_test/core/base/BaseFulWidget.dart';
import 'package:my_flutter_test/core/base/BaseLogic.dart';

import 'demo_logic.dart';

class Demo extends BaseFulWidget<DemoLogic> {
  // DemoLogic logic = Get.put(DemoLogic());

  @override
  Widget build(BuildContext context) {
    //读取数据vm
    return Scaffold(
        // Use Obx(()=> to update Text() whenever count is changed.
        appBar: AppBar(
            title: Obx(() => Text("Clicks: ${logic.count}   "
                "${logic.text}"))),

        // Replace the 8 lines Navigator.push by a simple Get.to(). You don't need context
        body: Center(
            child: Column(children: [
          Obx(() => Text('Running on ${logic.text}')),
          ElevatedButton(
              child: Text("设置count"),
              onPressed: () => {logic.setCount(111111)}),
          ElevatedButton(
              child: Text("设置文本"),
              onPressed: () => {logic.text.value = "bbbbbbb"}),
          ElevatedButton(
              child: Text("打开第二页"),
              onPressed: () => {Navigator.of(context).pushNamed('Demo2')})
        ])),
        floatingActionButton: FloatingActionButton(
            child: Icon(Icons.add), onPressed: logic.increment));
  }

  //初始化状态，但是如果使用了GetxController 就不需要了
  @override
  void initState() {}

  @override
  DemoLogic buildLogic() {
    return Get.put(DemoLogic());
  }
}
